package com.fandy.struts.util;

import java.io.*;

public class FileOperator {

	public static String SaveBytesToFile(byte[]  bt,String suffix, String appRoot)
	{
		String Name  ="Upload"+FileNameGenerator.generateFileName()+suffix;
		
		System.out.println(Name);
		
		try {
			
			File f= new File(appRoot+Name);
		
			
			
			f.createNewFile();
			
			System.out.println(f.getAbsoluteFile());
			
			FileOutputStream os = new FileOutputStream(appRoot+Name,false);
			
			
			 
			os.write(bt);
		} 
		catch(FileNotFoundException fne)
		{
			System.out.print(fne);			
		}
		
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return Name;
	}
	
	/*
	 * 
	 * 
	 */
	public static boolean DeleteFile(String FileName, String appRoot)
	{
		
		
			
			File f = new File(appRoot+File.pathSeparator+FileName.replace('/', File.pathSeparatorChar));
			f.delete();
					
		
		return true;
	}
	
}
